Skip to content

Fix workaround in Segmented control #699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

AndrewKeepCoding
Copy link
Contributor

This commit modifies the OnApplyTemplate method in the Segmented class to set SelectedIndex to -1 and then assign _internalSelectedIndex if _hasLoaded is false. This ensures the selected index is reset before applying the internal selection and marks the template as loaded.

Fixes

#698

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

The selected item is not rendered as selected when in XAML:

  • 2 SegmentedItems are declared
    and
  • SelectedIndex is set to 1.
<toolkit:Segmented SelectedIndex="1">
    <toolkit:SegmentedItem Content="Item 1" />
    <toolkit:SegmentedItem Content="Item 2" />
</toolkit:Segmented>

image

What is the new behavior?

The selected item is rendered as expected.
image

PR Checklist

Please check if your PR fulfills the following requirements:

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • Contains NO breaking changes

Other information

… template application

This commit modifies the `OnApplyTemplate` method in the `Segmented` class to set `SelectedIndex` to `-1` and then assign `_internalSelectedIndex` if `_hasLoaded` is false. This ensures the selected index is reset before applying the internal selection and marks the template as loaded.
@Arlodotexe Arlodotexe self-requested a review July 14, 2025 18:35
Copy link
Member

@Arlodotexe Arlodotexe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to reproduce the issue locally and have confirmed that this change fixes it. Thanks, approved!

@Arlodotexe Arlodotexe enabled auto-merge (squash) July 14, 2025 21:26
@Arlodotexe Arlodotexe merged commit 11280e0 into CommunityToolkit:main Jul 14, 2025
41 of 42 checks passed
@AndrewKeepCoding AndrewKeepCoding deleted the fix-segemented-control-workaround branch July 14, 2025 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants